package jp.co.technotree.dao.order.bean;

import java.text.SimpleDateFormat;

import jp.co.technotree.common.dao.BaseDAO;
import jp.co.technotree.common.dao.StatementBatchParameters;
import jp.co.technotree.common.dao.StatementParameters;
import jp.co.technotree.common.util.DBGLog;
import jp.co.technotree.exception.DataAccessException;
import jp.co.technotree.exception.DataAccessObjectException;


public class OrderUpdateDAO extends BaseDAO {
	private static String CLASSNAME=OrderUpdateDAO.class.getName();
	
	/**
	 * 新規IDの取得
	 * @return
	 * @throws DataAccessException
	 */
	public long getNewId() throws DataAccessException{
		String METHODNAME = "getNewId";
		//DBGLog.log(CLASSNAME,METHODNAME,"START");
		long newId=0;
		
		try {
			newId = execueSequence("hrs_order_id_seq");
		} catch (Exception e) {
			e.printStackTrace();
			throw new DataAccessObjectException(""+e.getMessage());
		}
		
		//DBGLog.log(CLASSNAME,METHODNAME,"END");
		return newId;
	}

	/**
	 * 新規IDの取得
	 * @return
	 * @throws DataAccessException
	 */
	public String getNewSeqOrderCd() throws DataAccessException{
		String METHODNAME = "getNewSeqOrderCd";
		//DBGLog.log(CLASSNAME,METHODNAME,"START");
		long newId=0;
		
		try {
			newId = execueSequence("hrs_order_order_cd_id_seq");
		} catch (Exception e) {
			e.printStackTrace();
			throw new DataAccessObjectException(""+e.getMessage());
		}
		//10000000
		//↓
		//100000
		
		String seqStr = Long.toString(newId, 36).toUpperCase();
		seqStr = "00000" + seqStr;
		seqStr = seqStr.substring(seqStr.length()-5, seqStr.length());
		
		//DBGLog.log(CLASSNAME,METHODNAME,"END");
		return seqStr;
	}
	
	/**
	 * アップデート処理
	 * 
	 * @param updateOrder
	 * @return
	 * @throws DataAccessException
	 */
	public int updateOrder(OrderBean[] orderBeanList) throws DataAccessException{
		String METHODNAME = "updateOrder";
		DBGLog.log(CLASSNAME,METHODNAME,"START");
		
		StatementParameters params = new StatementParameters();
		if (orderBeanList == null) {
			return 0;
		}
		
		String sql = "";

		sql += " update hrs_order_tbl set\n";
		//sql += " 	id={:ID}\n";
		sql += " 	info_kbn={:INFO_KBN}\n";
		sql += " 	,correct_cd={:CORRECT_CD}\n";
		sql += " 	,provision_kbn={:PROVISION_KBN}\n";
		sql += " 	,direct_kbn={:DIRECT_KBN}\n";
		sql += " 	,acpt_kbn={:ACPT_KBN}\n";
		sql += " 	,div_kbn={:DIV_KBN}\n";
		sql += " 	,report_cd={:REPORT_CD}\n";
		sql += " 	,page_no={:PAGE_NO}\n";
		sql += " 	,upload_id={:UPLOAD_ID}\n";
		sql += " 	,customer_cd={:CUSTOMER_CD}\n";
		sql += " 	,order_cd={:ORDER_CD}\n";
		sql += " 	,supplier_cd={:SUPPLIER_CD}\n";
		sql += " 	,supplier_name={:SUPPLIER_NAME}\n";
		sql += " 	,recv_date={:RECV_DATE}\n";
		sql += " 	,invoice_cd={:INVOICE_CD}\n";
		sql += " 	,sysitem_cd={:SYSITEM_CD}\n";
		sql += " 	,item_cd={:ITEM_CD}\n";
		sql += " 	,item_name={:ITEM_NAME}\n";
		sql += " 	,delivery_cd={:DELIVERY_CD}\n";
		sql += " 	,delivery_name={:DELIVERY_NAME}\n";
		sql += " 	,order_unit={:ORDER_UNIT}\n";
		sql += " 	,delivery_date={:DELIVERY_DATE}\n";
		sql += " 	,delivery_time={:DELIVERY_TIME}\n";
		sql += " 	,order_qty={:ORDER_QTY}\n";
		sql += " 	,order_price={:ORDER_PRICE}\n";
		sql += " 	,price_kbn={:PRICE_KBN}\n";
		sql += " 	,tax_kbn={:TAX_KBN}\n";
		sql += " 	,tax_rate={:TAX_RATE}\n";
		sql += " 	,cur_kbn={:CUR_KBN}\n";
		sql += " 	,subtotal_price={:SUBTOTAL_PRICE}\n";
		sql += " 	,tax_price={:TAX_PRICE}\n";
		sql += " 	,total_price={:TOTAL_PRICE}\n";
		sql += " 	,check_kbn={:CHECK_KBN}\n";
		sql += " 	,const_cd={:CONST_CD}\n";
		sql += " 	,custdeli_no={:CUSTDELI_NO}\n";
		sql += " 	,supply_dest={:SUPPLY_DEST}\n";
		sql += " 	,order_kbn={:ORDER_KBN}\n";
		sql += " 	,customer_name={:CUSTOMER_NAME}\n";
		sql += " 	,data1={:DATA1}\n";
		sql += " 	,data2={:DATA2}\n";
		sql += " 	,vendor_cd={:VENDOR_CD}\n";
		sql += " 	,note={:NOTE}\n";
		sql += " 	,error_cd={:ERROR_CD}\n";
		sql += " 	,create_emp_cd={:CREATE_EMP_CD}\n";
		sql += " 	,create_timestamp={:CREATE_TIMESTAMP}\n";
		sql += " 	,orderreport_cd={:ORDERREPORT_CD}\n";
		
		
		//--------#20090303
		sql += " 	,custdeli_date={:CUSTDELI_DATE}\n";
		sql += " 	,shiporder_date={:SHIPORDER_DATE}\n";
		//--------#20090303
		sql += " 	,warehouse_cd={:WAREHOUSE_CD}\n";
		
		sql += " where\n";
		sql += "  id={:ID}";
		int result = 0;
		int i;
		try {
			SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sdfTimestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			// バッチ処理用のステートメントをSQLから取得
			StatementBatchParameters stmtBatchParams = createUpdateStatement(sql);
			
			for ( i=0; i<orderBeanList.length; i++ ){
				OrderBean orderBean = orderBeanList[i];
				params = new StatementParameters();
				//orderBean.setId(getNewId());
				
				params.setLong("ID", orderBean.getId());
				params.setString("INFO_KBN", orderBean.getInfoKbn());
				params.setString("CORRECT_CD", orderBean.getCorrectCd());
				params.setString("PROVISION_KBN", orderBean.getProvisionKbn());
				params.setString("DIRECT_KBN", orderBean.getDirectKbn());
				params.setString("ACPT_KBN", orderBean.getAcptKbn());
				params.setString("DIV_KBN", orderBean.getDivKbn());
				params.setString("REPORT_CD", orderBean.getReportCd());
				params.setLong("PAGE_NO", orderBean.getPageNo());
				params.setLong("UPLOAD_ID", orderBean.getUploadId());
				params.setString("CUSTOMER_CD", orderBean.getCustomerCd());
				params.setString("ORDER_CD", orderBean.getOrderCd());
				params.setString("SUPPLIER_CD", orderBean.getSupplierCd());
				params.setString("SUPPLIER_NAME", orderBean.getSupplierName());
				params.setDate("RECV_DATE", orderBean.getRecvDate());
				params.setString("INVOICE_CD", orderBean.getInvoiceCd());
				params.setString("SYSITEM_CD", orderBean.getSysItemCd());
				params.setString("ITEM_CD", orderBean.getItemCd());
				params.setString("ITEM_NAME", orderBean.getItemName());
				params.setString("DELIVERY_CD", orderBean.getDeliveryCd());
				params.setString("DELIVERY_NAME", orderBean.getDeliveryName());
				params.setString("ORDER_UNIT", orderBean.getOrderUnit());
				params.setDate("DELIVERY_DATE", orderBean.getDeliveryDate());
				params.setTime("DELIVERY_TIME", orderBean.getDeliveryTime());
				params.setBigDecimal("ORDER_QTY", orderBean.getOrderQty());
				params.setBigDecimal("ORDER_PRICE", orderBean.getOrderPrice());
				params.setString("PRICE_KBN", orderBean.getPriceKbn());
				params.setString("TAX_KBN", orderBean.getTaxKbn());
				params.setBigDecimal("TAX_RATE", orderBean.getTaxRate());
				params.setString("CUR_KBN", orderBean.getCurKbn());
				params.setBigDecimal("SUBTOTAL_PRICE", orderBean.getSubtotalPrice());
				params.setBigDecimal("TAX_PRICE", orderBean.getTaxPrice());
				params.setBigDecimal("TOTAL_PRICE", orderBean.getTotalPrice());
				params.setString("CHECK_KBN", orderBean.getCheckKbn());
				params.setString("CONST_CD", orderBean.getConstCd());
				params.setString("CUSTDELI_NO", orderBean.getCustdeliNo());
				params.setString("SUPPLY_DEST", orderBean.getSupplyDest());
				params.setString("ORDER_KBN", orderBean.getOrderKbn());
				params.setString("CUSTOMER_NAME", orderBean.getCustomerName());
				params.setString("DATA1", orderBean.getData1());
				params.setString("DATA2", orderBean.getData2());
				params.setString("VENDOR_CD", orderBean.getVendorCd());
				params.setString("NOTE", orderBean.getNote());
				params.setString("ERROR_CD", orderBean.getErrorCd());
				params.setString("CREATE_EMP_CD", orderBean.getCreateEmpCd());
				params.setTimestamp("CREATE_TIMESTAMP", orderBean.getCreateTimestamp());
				params.setString("ORDERREPORT_CD", orderBean.getOrderreportCd());
				//--------#20090303
				params.setDate("CUSTDELI_DATE", orderBean.getCustdeliDate());
				params.setDate("SHIPORDER_DATE", orderBean.getShiporderDate());
				//--------#20090303

				params.setString("WAREHOUSE_CD", orderBean.getWarehouseCd());

//				DBGLog.log(CLASSNAME,METHODNAME,"SQL:"+sql);

				// バッチ処理にSQLを登録する
				addUpdateSQL(stmtBatchParams, params);
			}
			
			// バッチ処理を実行
			result = executeUpdateSQL(stmtBatchParams);
			if ( result == 0 ){
				DBGLog.log(CLASSNAME,METHODNAME,"データ更新なし");
			}

		} catch (DataAccessObjectException e) {
			e.printStackTrace();
		}

		DBGLog.log(CLASSNAME, METHODNAME, "END");
		return result;
	}
	
	/**
	 * インサート処理
	 * 
	 * @param insertOrder
	 * @return
	 * @throws DataAccessException
	 */
	public int insertOrder(OrderBean[] orderBeanList) throws DataAccessException{
		String METHODNAME = "insertOrder";
		DBGLog.log(CLASSNAME,METHODNAME,"START");
		
		StatementParameters params = new StatementParameters();
		if (orderBeanList == null) {
			return 0;
		}
		
		String sql = "";

		sql += " insert into hrs_order_tbl (\n";
		sql += " 	id\n";
		sql += " 	,info_kbn\n";
		sql += " 	,correct_cd\n";
		sql += " 	,provision_kbn\n";
		sql += " 	,direct_kbn\n";
		sql += " 	,acpt_kbn\n";
		sql += " 	,div_kbn\n";
		sql += " 	,report_cd\n";
		sql += " 	,page_no\n";
		sql += " 	,upload_id\n";
		sql += " 	,customer_cd\n";
		sql += " 	,order_cd\n";
		sql += " 	,supplier_cd\n";
		sql += " 	,supplier_name\n";
		sql += " 	,recv_date\n";
		sql += " 	,invoice_cd\n";
		sql += " 	,sysitem_cd\n";
		sql += " 	,item_cd\n";
		sql += " 	,item_name\n";
		sql += " 	,delivery_cd\n";
		sql += " 	,delivery_name\n";
		sql += " 	,order_unit\n";
		sql += " 	,delivery_date\n";
		sql += " 	,delivery_time\n";
		sql += " 	,order_qty\n";
		sql += " 	,order_price\n";
		sql += " 	,price_kbn\n";
		sql += " 	,tax_kbn\n";
		sql += " 	,tax_rate\n";
		sql += " 	,cur_kbn\n";
		sql += " 	,subtotal_price\n";
		sql += " 	,tax_price\n";
		sql += " 	,total_price\n";
		sql += " 	,check_kbn\n";
		sql += " 	,const_cd\n";
		sql += " 	,custdeli_no\n";
		sql += " 	,supply_dest\n";
		sql += " 	,order_kbn\n";
		sql += " 	,customer_name\n";
		sql += " 	,data1\n";
		sql += " 	,data2\n";
		sql += " 	,vendor_cd\n";
		sql += " 	,note\n";
		sql += " 	,error_cd\n";
		sql += " 	,create_emp_cd\n";
		sql += " 	,create_timestamp\n";
		sql += " 	,orderreport_cd\n";
		
		
		//--------#20090303
		sql += " 	,custdeli_date\n";
		sql += " 	,shiporder_date\n";
		//--------#20090303
		sql += " 	,warehouse_cd\n";

		sql += " ) values (\n";
		sql += " 	{:ID}\n";
		sql += " 	,{:INFO_KBN}\n";
		sql += " 	,{:CORRECT_CD}\n";
		sql += " 	,{:PROVISION_KBN}\n";
		sql += " 	,{:DIRECT_KBN}\n";
		sql += " 	,{:ACPT_KBN}\n";
		sql += " 	,{:DIV_KBN}\n";
		sql += " 	,{:REPORT_CD}\n";
		sql += " 	,{:PAGE_NO}\n";
		sql += " 	,{:UPLOAD_ID}\n";
		sql += " 	,{:CUSTOMER_CD}\n";
		sql += " 	,{:ORDER_CD}\n";
		sql += " 	,{:SUPPLIER_CD}\n";
		sql += " 	,{:SUPPLIER_NAME}\n";
		sql += " 	,{:RECV_DATE}\n";
		sql += " 	,{:INVOICE_CD}\n";
		sql += " 	,{:SYSITEM_CD}\n";
		sql += " 	,{:ITEM_CD}\n";
		sql += " 	,{:ITEM_NAME}\n";
		sql += " 	,{:DELIVERY_CD}\n";
		sql += " 	,{:DELIVERY_NAME}\n";
		sql += " 	,{:ORDER_UNIT}\n";
		sql += " 	,{:DELIVERY_DATE}\n";
		sql += " 	,{:DELIVERY_TIME}\n";
		sql += " 	,{:ORDER_QTY}\n";
		sql += " 	,{:ORDER_PRICE}\n";
		sql += " 	,{:PRICE_KBN}\n";
		sql += " 	,{:TAX_KBN}\n";
		sql += " 	,{:TAX_RATE}\n";
		sql += " 	,{:CUR_KBN}\n";
		sql += " 	,{:SUBTOTAL_PRICE}\n";
		sql += " 	,{:TAX_PRICE}\n";
		sql += " 	,{:TOTAL_PRICE}\n";
		sql += " 	,{:CHECK_KBN}\n";
		sql += " 	,{:CONST_CD}\n";
		sql += " 	,{:CUSTDELI_NO}\n";
		sql += " 	,{:SUPPLY_DEST}\n";
		sql += " 	,{:ORDER_KBN}\n";
		sql += " 	,{:CUSTOMER_NAME}\n";
		sql += " 	,{:DATA1}\n";
		sql += " 	,{:DATA2}\n";
		sql += " 	,{:VENDOR_CD}\n";
		sql += " 	,{:NOTE}\n";
		sql += " 	,{:ERROR_CD}\n";
		sql += " 	,{:CREATE_EMP_CD}\n";
		sql += " 	,{:CREATE_TIMESTAMP}\n";
		sql += " 	,{:ORDERREPORT_CD}\n";
		//--------#20090303
		sql += " 	,{:CUSTDELI_DATE}\n";
		sql += " 	,{:SHIPORDER_DATE}\n";
		//--------#20090303
		
		sql += " 	,{:WAREHOUSE_CD}\n";
		sql += " )\n";
		
		int result = 0;
		int i;
		try {
			SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sdfTimestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			// バッチ処理用のステートメントをSQLから取得
			StatementBatchParameters stmtBatchParams = createUpdateStatement(sql);
			
			for ( i=0; i<orderBeanList.length; i++ ){
				OrderBean orderBean = orderBeanList[i];
				params = new StatementParameters();
				orderBean.setId(getNewId());
				
				params.setLong("ID", orderBean.getId());
				params.setString("INFO_KBN", orderBean.getInfoKbn());
				params.setString("CORRECT_CD", orderBean.getCorrectCd());
				params.setString("PROVISION_KBN", orderBean.getProvisionKbn());
				params.setString("DIRECT_KBN", orderBean.getDirectKbn());
				params.setString("ACPT_KBN", orderBean.getAcptKbn());
				params.setString("DIV_KBN", orderBean.getDivKbn());
				params.setString("REPORT_CD", orderBean.getReportCd());
				params.setLong("PAGE_NO", orderBean.getPageNo());
				params.setLong("UPLOAD_ID", orderBean.getUploadId());
				params.setString("CUSTOMER_CD", orderBean.getCustomerCd());
				params.setString("ORDER_CD", orderBean.getOrderCd());
				params.setString("SUPPLIER_CD", orderBean.getSupplierCd());
				params.setString("SUPPLIER_NAME", orderBean.getSupplierName());
				params.setDate("RECV_DATE", orderBean.getRecvDate());
				params.setString("INVOICE_CD", orderBean.getInvoiceCd());
				params.setString("SYSITEM_CD", orderBean.getSysItemCd());
				params.setString("ITEM_CD", orderBean.getItemCd());
				params.setString("ITEM_NAME", orderBean.getItemName());
				params.setString("DELIVERY_CD", orderBean.getDeliveryCd());
				params.setString("DELIVERY_NAME", orderBean.getDeliveryName());
				params.setString("ORDER_UNIT", orderBean.getOrderUnit());
				params.setDate("DELIVERY_DATE", orderBean.getDeliveryDate());
				params.setTime("DELIVERY_TIME", orderBean.getDeliveryTime());
				params.setBigDecimal("ORDER_QTY", orderBean.getOrderQty());
				params.setBigDecimal("ORDER_PRICE", orderBean.getOrderPrice());
				params.setString("PRICE_KBN", orderBean.getPriceKbn());
				params.setString("TAX_KBN", orderBean.getTaxKbn());
				params.setBigDecimal("TAX_RATE", orderBean.getTaxRate());
				params.setString("CUR_KBN", orderBean.getCurKbn());
				params.setBigDecimal("SUBTOTAL_PRICE", orderBean.getSubtotalPrice());
				params.setBigDecimal("TAX_PRICE", orderBean.getTaxPrice());
				params.setBigDecimal("TOTAL_PRICE", orderBean.getTotalPrice());
				params.setString("CHECK_KBN", orderBean.getCheckKbn());
				params.setString("CONST_CD", orderBean.getConstCd());
				params.setString("CUSTDELI_NO", orderBean.getCustdeliNo());
				params.setString("SUPPLY_DEST", orderBean.getSupplyDest());
				params.setString("ORDER_KBN", orderBean.getOrderKbn());
				params.setString("CUSTOMER_NAME", orderBean.getCustomerName());
				params.setString("DATA1", orderBean.getData1());
				params.setString("DATA2", orderBean.getData2());
				params.setString("VENDOR_CD", orderBean.getVendorCd());
				params.setString("NOTE", orderBean.getNote());
				params.setString("ERROR_CD", orderBean.getErrorCd());
				params.setString("CREATE_EMP_CD", orderBean.getCreateEmpCd());
				params.setTimestamp("CREATE_TIMESTAMP", orderBean.getCreateTimestamp());
				params.setString("ORDERREPORT_CD", orderBean.getOrderreportCd());
				//--------#20090303
				params.setDate("CUSTDELI_DATE", orderBean.getCustdeliDate());
				params.setDate("SHIPORDER_DATE", orderBean.getShiporderDate());
				//--------#20090303

				params.setString("WAREHOUSE_CD", orderBean.getWarehouseCd());

//				DBGLog.log(CLASSNAME,METHODNAME,"SQL:"+sql);

				// バッチ処理にSQLを登録する
				addUpdateSQL(stmtBatchParams, params);
			}
			
			// バッチ処理を実行
			result = executeUpdateSQL(stmtBatchParams);
			if ( result == 0 ){
				DBGLog.log(CLASSNAME,METHODNAME,"データ更新なし");
			}

		} catch (DataAccessObjectException e) {
			e.printStackTrace();
		}

		DBGLog.log(CLASSNAME, METHODNAME, "END");
		return result;
	}
	
	/**
	 * インサート処理
	 * 
	 * @param insertOrder
	 * @return
	 * @throws DataAccessException
	 */
	public int insertMygOrder(OrderBean[] orderBeanList,String orderType) throws DataAccessException{
		String METHODNAME = "insertOrder";
		DBGLog.log(CLASSNAME,METHODNAME,"START");
		
		StatementParameters params = new StatementParameters();
		if (orderBeanList == null) {
			return 0;
		}
		
		String sql = "";

		sql += " insert into hrs_order_tbl (\n";
		sql += " 	id\n";
		sql += " 	,info_kbn\n";
		sql += " 	,correct_cd\n";
		sql += " 	,provision_kbn\n";
		sql += " 	,direct_kbn\n";
		sql += " 	,acpt_kbn\n";
		sql += " 	,div_kbn\n";
		sql += " 	,report_cd\n";
		sql += " 	,page_no\n";
		sql += " 	,upload_id\n";
		sql += " 	,customer_cd\n";
		sql += " 	,order_cd\n";
		sql += " 	,supplier_cd\n";
		sql += " 	,supplier_name\n";
		sql += " 	,recv_date\n";
		sql += " 	,invoice_cd\n";
		sql += " 	,sysitem_cd\n";
		sql += " 	,item_cd\n";
		sql += " 	,item_name\n";
		sql += " 	,delivery_cd\n";
		sql += " 	,delivery_name\n";
		sql += " 	,order_unit\n";
		sql += " 	,delivery_date\n";
		sql += " 	,delivery_time\n";
		sql += " 	,order_qty\n";
		sql += " 	,order_price\n";
		sql += " 	,price_kbn\n";
		sql += " 	,tax_kbn\n";
		sql += " 	,tax_rate\n";
		sql += " 	,cur_kbn\n";
		sql += " 	,subtotal_price\n";
		sql += " 	,tax_price\n";
		sql += " 	,total_price\n";
		sql += " 	,check_kbn\n";
		sql += " 	,const_cd\n";
		sql += " 	,custdeli_no\n";
		sql += " 	,supply_dest\n";
		sql += " 	,order_kbn\n";
		sql += " 	,customer_name\n";
		sql += " 	,data1\n";
		sql += " 	,data2\n";
		sql += " 	,vendor_cd\n";
		sql += " 	,note\n";
		sql += " 	,error_cd\n";
		sql += " 	,create_emp_cd\n";
		sql += " 	,create_timestamp\n";
		sql += " 	,orderreport_cd\n";
		
		
		//--------#20090303
		sql += " 	,custdeli_date\n";
		sql += " 	,shiporder_date\n";
		//--------#20090303
		sql += " 	,warehouse_cd\n";

		sql += " ) values (\n";
		sql += " 	{:ID}\n";
		sql += " 	,{:INFO_KBN}\n";
		sql += " 	,{:CORRECT_CD}\n";
		sql += " 	,{:PROVISION_KBN}\n";
		sql += " 	,{:DIRECT_KBN}\n";
		sql += " 	,{:ACPT_KBN}\n";
		sql += " 	,{:DIV_KBN}\n";
		sql += " 	,{:REPORT_CD}\n";
		sql += " 	,{:PAGE_NO}\n";
		sql += " 	,{:UPLOAD_ID}\n";
		sql += " 	,{:CUSTOMER_CD}\n";
		sql += " 	,{:ORDER_CD}\n";
		sql += " 	,{:SUPPLIER_CD}\n";
		sql += " 	,{:SUPPLIER_NAME}\n";
		sql += " 	,{:RECV_DATE}\n";
		sql += " 	,{:INVOICE_CD}\n";
		sql += " 	,{:SYSITEM_CD}\n";
		sql += " 	,{:ITEM_CD}\n";
		sql += " 	,{:ITEM_NAME}\n";
		sql += " 	,{:DELIVERY_CD}\n";
		sql += " 	,{:DELIVERY_NAME}\n";
		sql += " 	,{:ORDER_UNIT}\n";
		sql += " 	,{:DELIVERY_DATE}\n";
		sql += " 	,{:DELIVERY_TIME}\n";
		sql += " 	,{:ORDER_QTY}\n";
		sql += " 	,{:ORDER_PRICE}\n";
		sql += " 	,{:PRICE_KBN}\n";
		sql += " 	,{:TAX_KBN}\n";
		sql += " 	,{:TAX_RATE}\n";
		sql += " 	,{:CUR_KBN}\n";
		sql += " 	,{:SUBTOTAL_PRICE}\n";
		sql += " 	,{:TAX_PRICE}\n";
		sql += " 	,{:TOTAL_PRICE}\n";
		sql += " 	,{:CHECK_KBN}\n";
		sql += " 	,{:CONST_CD}\n";
		sql += " 	,{:CUSTDELI_NO}\n";
		sql += " 	,{:SUPPLY_DEST}\n";
		sql += " 	,{:ORDER_KBN}\n";
		sql += " 	,{:CUSTOMER_NAME}\n";
		sql += " 	,{:DATA1}\n";
		sql += " 	,{:DATA2}\n";
		sql += " 	,{:VENDOR_CD}\n";
		sql += " 	,{:NOTE}\n";
		sql += " 	,{:ERROR_CD}\n";
		sql += " 	,{:CREATE_EMP_CD}\n";
		sql += " 	,{:CREATE_TIMESTAMP}\n";
		sql += " 	,{:ORDERREPORT_CD}\n";
		//--------#20090303
		sql += " 	,{:CUSTDELI_DATE}\n";
		sql += " 	,{:SHIPORDER_DATE}\n";
		//--------#20090303
		
		sql += " 	,{:WAREHOUSE_CD}\n";
		sql += " )\n";
		
		int result = 0;
		int i;
		try {
			SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sdfTimestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			// バッチ処理用のステートメントをSQLから取得
			StatementBatchParameters stmtBatchParams = createUpdateStatement(sql);
			
			for ( i=0; i<orderBeanList.length; i++ ){
				OrderBean orderBean = orderBeanList[i];
				params = new StatementParameters();
				orderBean.setId(getNewId());
				if (orderBean.getInvoiceCd() == null || "".equals(orderBean.getInvoiceCd())){
					orderBean.setInvoiceCd(orderType+"-"+orderBean.getId());
				}
				if (orderBean.getOrderCd() == null || "".equals(orderBean.getOrderCd())){
					orderBean.setOrderCd(orderBean.getCustomerCd()+orderBean.getInvoiceCd());
				}
				
				params.setLong("ID", orderBean.getId());
				params.setString("INFO_KBN", orderBean.getInfoKbn());
				params.setString("CORRECT_CD", orderBean.getCorrectCd());
				params.setString("PROVISION_KBN", orderBean.getProvisionKbn());
				params.setString("DIRECT_KBN", orderBean.getDirectKbn());
				params.setString("ACPT_KBN", orderBean.getAcptKbn());
				params.setString("DIV_KBN", orderBean.getDivKbn());
				params.setString("REPORT_CD", orderBean.getReportCd());
				params.setLong("PAGE_NO", orderBean.getPageNo());
				params.setLong("UPLOAD_ID", orderBean.getUploadId());
				params.setString("CUSTOMER_CD", orderBean.getCustomerCd());
				params.setString("ORDER_CD", orderBean.getOrderCd());
				params.setString("SUPPLIER_CD", orderBean.getSupplierCd());
				params.setString("SUPPLIER_NAME", orderBean.getSupplierName());
				params.setDate("RECV_DATE", orderBean.getRecvDate());
				params.setString("INVOICE_CD", orderBean.getInvoiceCd());
				params.setString("SYSITEM_CD", orderBean.getSysItemCd());
				params.setString("ITEM_CD", orderBean.getItemCd());
				params.setString("ITEM_NAME", orderBean.getItemName());
				params.setString("DELIVERY_CD", orderBean.getDeliveryCd());
				params.setString("DELIVERY_NAME", orderBean.getDeliveryName());
				params.setString("ORDER_UNIT", orderBean.getOrderUnit());
				params.setDate("DELIVERY_DATE", orderBean.getDeliveryDate());
				params.setTime("DELIVERY_TIME", orderBean.getDeliveryTime());
				params.setBigDecimal("ORDER_QTY", orderBean.getOrderQty());
				params.setBigDecimal("ORDER_PRICE", orderBean.getOrderPrice());
				params.setString("PRICE_KBN", orderBean.getPriceKbn());
				params.setString("TAX_KBN", orderBean.getTaxKbn());
				params.setBigDecimal("TAX_RATE", orderBean.getTaxRate());
				params.setString("CUR_KBN", orderBean.getCurKbn());
				params.setBigDecimal("SUBTOTAL_PRICE", orderBean.getSubtotalPrice());
				params.setBigDecimal("TAX_PRICE", orderBean.getTaxPrice());
				params.setBigDecimal("TOTAL_PRICE", orderBean.getTotalPrice());
				params.setString("CHECK_KBN", orderBean.getCheckKbn());
				params.setString("CONST_CD", orderBean.getConstCd());
				params.setString("CUSTDELI_NO", orderBean.getCustdeliNo());
				params.setString("SUPPLY_DEST", orderBean.getSupplyDest());
				params.setString("ORDER_KBN", orderBean.getOrderKbn());
				params.setString("CUSTOMER_NAME", orderBean.getCustomerName());
				params.setString("DATA1", orderBean.getData1());
				params.setString("DATA2", orderBean.getData2());
				params.setString("VENDOR_CD", orderBean.getVendorCd());
				params.setString("NOTE", orderBean.getNote());
				params.setString("ERROR_CD", orderBean.getErrorCd());
				params.setString("CREATE_EMP_CD", orderBean.getCreateEmpCd());
				params.setTimestamp("CREATE_TIMESTAMP", orderBean.getCreateTimestamp());
				params.setString("ORDERREPORT_CD", orderBean.getOrderreportCd());
				//--------#20090303
				params.setDate("CUSTDELI_DATE", orderBean.getCustdeliDate());
				params.setDate("SHIPORDER_DATE", orderBean.getShiporderDate());
				//--------#20090303

				params.setString("WAREHOUSE_CD", orderBean.getWarehouseCd());

//				DBGLog.log(CLASSNAME,METHODNAME,"SQL:"+sql);

				// バッチ処理にSQLを登録する
				addUpdateSQL(stmtBatchParams, params);
			}
			
			// バッチ処理を実行
			result = executeUpdateSQL(stmtBatchParams);
			if ( result == 0 ){
				DBGLog.log(CLASSNAME,METHODNAME,"データ更新なし");
			}

		} catch (DataAccessObjectException e) {
			e.printStackTrace();
		}

		DBGLog.log(CLASSNAME, METHODNAME, "END");
		return result;
	}
	

	/**
	 * 削除処理
	 * 
	 * @param deleteOrder
	 * @return
	 * @throws DataAccessException
	 */
	public int deleteOrder(String reportCd) throws DataAccessException{
		String METHODNAME = "deleteOrder";
		DBGLog.log(CLASSNAME,METHODNAME,"START");
		
		if (reportCd == null || reportCd.equals("")) {
			return 0;
		}
		String sql = null;
		sql = "delete\n";
		sql += "from\n";
		sql += "	hrs_order_tbl\n";
		sql += "where\n";
		sql += "	report_cd = '"+reportCd+"'\n";

		int result = 0;
		try {
			
			result += executeUpdateSQL(sql);

		} catch (DataAccessObjectException e) {
			e.printStackTrace();
		}

		DBGLog.log(CLASSNAME, METHODNAME, "END");
		return result;
	}
	
	/**
	 * ベースDAOの奥深いところ改造時のテスト
	 * 
	 * インサート処理
	 * 
	 * @param insertOrder
	 * @return
	 * @throws DataAccessException
	 */
	public int insertOrderrrrrrrrrrrrr(OrderBean[] orderBeanList) throws DataAccessException{
		String METHODNAME = "insertOrder";
		DBGLog.log(CLASSNAME,METHODNAME,"START");
		
		StatementParameters params = new StatementParameters();
		if (orderBeanList == null) {
			return 0;
		}
		
		String sql = "";

		sql += "insert into hrs_order_tbl (\n";
		sql += "	id\n";
		sql += "	,delivery_date,delivery_time\n";
		sql += "	,note\n";
		sql += ") values (\n";
		sql += "	{:ID}\n";
		sql += "	,{:DELIVERY_DATE},{:DELIVERY_TIME}\n";
		sql += "	,{:NOTE}\n";
		sql += ")\n";
		
		int result = 0;
		int i;
		try {
			SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat sdfTimestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			for ( i=0; i<orderBeanList.length; i++ ){
				OrderBean orderBean = orderBeanList[i];
				params = new StatementParameters();
				orderBean.setId(getNewId());
				
				params.setLong("ID"	,orderBean.getId());
				params.setDate("DELIVERY_DATE"	,orderBean.getDeliveryDate());
				params.setTime("DELIVERY_TIME"	,orderBean.getDeliveryTime());
				params.setString("NOTE"				,orderBean.getNote());
				
				result += executeUpdateSQL(sql, params);
				if (result == 0) {
					DBGLog.log(CLASSNAME, METHODNAME, "データ更新なし");
				}
			}

		} catch (DataAccessObjectException e) {
			e.printStackTrace();
		}

		DBGLog.log(CLASSNAME, METHODNAME, "END");
		return result;
	}
	
	/**
	 * 注文一覧エクセル発行時の、レポート番号更新
	 * 
	 * @param beanList
	 * @return
	 * @throws DataAccessException
	 */
	public int updateOrderOrderreportCd(OrderBean[] beanList) throws DataAccessException{
		String METHODNAME = "updateOrderOrderreportCd";
		DBGLog.log(CLASSNAME,METHODNAME,"START");
		
		StatementParameters params = new StatementParameters();
		if (beanList == null) {
			return 0;
		}
		
		int result = 0;
		String sql = "";
		
		sql = " update hrs_order_tbl \n";
		sql += " set \n";
		sql += " orderreport_cd = {:ORDERREPORT_CD} \n";
		sql += " where \n";
		sql += " id = {:ID} \n";
		
		int i;
		try {
			// バッチ処理用のステートメントをSQLから取得
			StatementBatchParameters stmtBatchParams = createUpdateStatement(sql);

			for ( i=0; i<beanList.length; i++ ){
				OrderBean bean = beanList[i];
				params = new StatementParameters();
				
				// パラメータセット
				params.setLong("ID",bean.getId());
				params.setString("ORDERREPORT_CD",bean.getOrderreportCd());
				
				// バッチ処理にSQLを登録する
				addUpdateSQL(stmtBatchParams, params);
			}
			// バッチ処理を実行
			result = executeUpdateSQL(stmtBatchParams);
			if ( result == 0 ){
				DBGLog.log(CLASSNAME,METHODNAME,"データ更新なし");
			}
		} catch (DataAccessObjectException e) {
			e.printStackTrace();
		}

		DBGLog.log(CLASSNAME, METHODNAME, "END");
		return result;
	}
	
	/**
	 * 注文一覧エクセル発行時の、レポート番号更新
	 * 
	 * @param beanList
	 * @return
	 * @throws DataAccessException
	 */
	public int updateOrderOrderreportCdCancel(String[] orderreportCdList) throws DataAccessException{
		String METHODNAME = "updateOrderOrderreportCd";
		DBGLog.log(CLASSNAME,METHODNAME,"START");
		
		StatementParameters params = new StatementParameters();
		if (orderreportCdList == null) {
			return 0;
		}
		if (orderreportCdList.length == 0) {
			return 0;
		}
		
		int result = 0;
		String sql = "";
		
		sql = " update hrs_order_tbl \n";
		sql += " set \n";
		sql += " orderreport_cd = 'N' \n";
		sql += " where \n";
		sql += " orderreport_cd = {:ORDERREPORT_CD} \n";
		
		int i;
		try {
			// バッチ処理用のステートメントをSQLから取得
			StatementBatchParameters stmtBatchParams = createUpdateStatement(sql);

			for ( i=0; i<orderreportCdList.length; i++ ){
				String orderreportCd = orderreportCdList[i];
				params = new StatementParameters();
				
				// パラメータセット
				params.setString("ORDERREPORT_CD", orderreportCd);
				
				// バッチ処理にSQLを登録する
				addUpdateSQL(stmtBatchParams, params);
			}
			// バッチ処理を実行
			result = executeUpdateSQL(stmtBatchParams);
			if ( result == 0 ){
				DBGLog.log(CLASSNAME,METHODNAME,"データ更新なし");
			}
		} catch (DataAccessObjectException e) {
			e.printStackTrace();
		}

		DBGLog.log(CLASSNAME, METHODNAME, "END");
		return result;
	}
	
	
	/**
	 * 受注の削除した時の処理
	 * 
	 * @param beanList
	 * @return
	 * @throws DataAccessException
	 */
	public int updateOrderDeleteFlg(String orderCd) throws DataAccessException{
		String METHODNAME = "updateOrderDeleteFlg";
		DBGLog.log(CLASSNAME,METHODNAME,"START");
		
		StatementParameters params = new StatementParameters();
		if (orderCd == null) {
			return 0;
		}
		
		int result = 0;
		String sql = "";
		
		sql = " update hrs_order_tbl \n";
		sql += " set \n";
		sql += " enable_cate = '1' \n";
		sql += " where \n";
		sql += " order_cd = {:ORDER_CD} \n";
		
		int i;
		try {
			// バッチ処理用のステートメントをSQLから取得
			StatementBatchParameters stmtBatchParams = createUpdateStatement(sql);
			params = new StatementParameters();
			// パラメータセット
			params.setString("ORDER_CD",orderCd);
			// バッチ処理にSQLを登録する
			addUpdateSQL(stmtBatchParams, params);
			
//			for ( i=0; i<beanList.length; i++ ){
//				OrderBean bean = beanList[i];
//				params = new StatementParameters();
//				
//				// パラメータセット
//				params.setLong("ID",bean.getId());
//				params.setString("ORDER_CD",bean.getOrderreportCd());
//				
//				// バッチ処理にSQLを登録する
//				addUpdateSQL(stmtBatchParams, params);
//			}
			// バッチ処理を実行
			result = executeUpdateSQL(stmtBatchParams);
			if ( result == 0 ){
				DBGLog.log(CLASSNAME,METHODNAME,"データ更新なし");
			}
		} catch (DataAccessObjectException e) {
			e.printStackTrace();
		}

		DBGLog.log(CLASSNAME, METHODNAME, "END");
		return result;
	}
	
	
}
